#pragma once

#include <QtGui/QSyntaxHighlighter>




namespace Engine
{
	namespace Edit
	{
		/**
		 * This class can be used as a base for most code highlighters.
		 * It defines basic rules, as well as several default formating rules.
		 */
		class BasicCodeHighlighter
			: public QSyntaxHighlighter
		{
		public:

			SHARED(BasicCodeHighlighter);

			enum BasicType
			{
				StringConstant, //< String constant: "*"
				Comment, //< Both single and multiline comments

				Default,
			};



			BasicCodeHighlighter(QTextDocument *parent);
			virtual ~BasicCodeHighlighter();



			/**
			 * @returns the font for unmatched text
			 */
			QFont font() const;


			/**
			 * Highlights the given text.
			 */
			virtual void highlightBlock(const QString &text);

		protected:

			struct Rule
			{
				QRegExp pattern;
				QTextCharFormat format;
			};

			typedef QVector<Rule>   Rules;

			/**
			 * Adds the given rule to the list of highlighting rules.
			 * The rule is added to the end.
			 */
			void add(const Rule& rule);

			/**
			 * @returns the formatting to use for a token of the given type
			 *
			 * @note a subclass may want to use format(Default) as a base for other types
			 */
			QTextCharFormat basicFormat(BasicType type) const;

		private:

			QFont             m_font;

			Rules             m_rules;

			QRegExp           m_commentStartExpression;
			QRegExp           m_commentEndExpression;

			QTextCharFormat   m_defaultFormat;
			QTextCharFormat   m_singleLineCommentFormat;
			QTextCharFormat   m_multiLineCommentFormat;
			QTextCharFormat   m_commentFormat;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
